// 用户管理
const router = require("express").Router();
const { requestMiddleware } = require("../../utils").middleware;
const { user } = require("../../api/serverApi");
const {
  adminLogin,
  findUser,
  addUser,
  updateUser,
  delUser,
} = require("./bussiness");
const { checkToken } = require("../../utils/token");
// 管理员登录
router.use(user.adminLogin, requestMiddleware, adminLogin, (_, res) => {
  res.sendMsg && res.sendMsg();
});
// 用户列表
router.use(user.userList, requestMiddleware, checkToken, findUser, (_, res) => {
  res.sendMsg && res.sendMsg();
});
// 增加用户
router.use(user.addUser, requestMiddleware, checkToken, addUser, (_, res) => {
  res.sendMsg && res.sendMsg();
});
// 冻结、激活用户,修改用户
router.use(
  user.updateUser,
  requestMiddleware,
  checkToken,
  updateUser,
  (_, res) => {
    res.sendMsg && res.sendMsg();
  }
);
// 删除用户
router.use(user.delUser, requestMiddleware, checkToken, delUser, (_, res) => {
  res.sendMsg && res.sendMsg();
});

module.exports = router;
